package com.edu.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author yanzhao
 * @since 2021/6/17
 */
public class ExceptionPointer {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionPointer.class);

    private static final String PACKAGE_PREFIX = "com.edu.";

    /**
     * 输出报错的位置
     *
     * @param e
     * @param desc
     */
    public static void echo(Exception e, String desc) {
        StackTraceElement[] stackTrace = e.getStackTrace();
        for (int i = 0; i < stackTrace.length; i++) {
            String pointer = stackTrace[i].toString();
            if (pointer.startsWith(PACKAGE_PREFIX)) {
                LOGGER.error("{}：{}=>{}", desc, pointer, e.getMessage());
                return;
            }
        }
        LOGGER.error("{}：{}", desc, e.getMessage());
    }
}
